package ua.com.globallogic.basecamp.krasnyanskiy.anagrams.ioutils;

import ua.com.globallogic.basecamp.krasnyanskiy.anagrams.Anagram;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Set;

public class AnagramFileWriter {
    public void write(Set<Anagram> anagrams) throws IOException {
        File file = new File("anagrams.txt");
        if (!file.exists()) {
            file.createNewFile();
        }
        FileWriter fw = new FileWriter(file.getAbsoluteFile());
        BufferedWriter bw = new BufferedWriter(fw);
        for (Anagram anagram : anagrams) {
            bw.write(anagram.toString());
        }
        bw.close();
    }
}
